﻿using System;
using System.Collections.Generic;
using System.Composition;
using Unread.Business.Data.Storage.Interfaces;
using Windows.Foundation;
using Windows.Storage;
using Windows.Storage.Pickers;

namespace Unread.App.Services
{
    [Export(typeof(IFileReadPicker))]
    internal class FileReadPicker : IFileReadPicker
    {
        private readonly Windows.Storage.Pickers.FileOpenPicker _fileOpenPicker;

        public FileReadPicker()
        {
            _fileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
        }

        public IAsyncOperation<StorageFile> PickSingleFileAsync(PickerViewMode viewmode, PickerLocationId startLocation, IList<string> fileTypes)
        {
            if (fileTypes == null) throw new ArgumentNullException("fileTypes");

            _fileOpenPicker.ViewMode = viewmode;
            _fileOpenPicker.SuggestedStartLocation = startLocation;

            foreach (var fileType in fileTypes)
	        {
                _fileOpenPicker.FileTypeFilter.Add(fileType);
	        }

            return _fileOpenPicker.PickSingleFileAsync();
        }
    }
}
